<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
</head>

<body class='labelAuto'>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">人力资源管理</a>
            <a>
                <cite>请假列表</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
            onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body search">
                        <form action="" class="layui-form livingList">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">工种</label>
                                    <div class="layui-input-block">
                                        <select name="city" lay-verify="required" id="peopleType">
                                            <option value="0">-</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">搜索</label>
                                    <div class="layui-input-block">
                                        <input type="search" autocomplete="off" placeholder="输入工人姓名/工号" class="layui-input" id="search">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn search" type="button" id='search'>
                                        <i class="iconfont layui-icon">&#xe615;</i>
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body tableCardBody">
                        <table class="layui-table" id="lists" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type='text/html' id='toolbar'>
    <button class='applicationForLeave layui-btn' auth='leavingApply'>请假申请</button>
</script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        $('#peopleType').append(professionSelect());
        form.render();
        var projectId = Number($.parseJSON(localStorage.getItem('login_msg')).projectId);
        // 异步数据加载
        var lists = table.render({
            elem: '#lists', //绑定DOM元素
            id: 'lists', //table的id
            title: '人员列表',
            height: 'full-150',
            contentType: "application/json; charset=utf-8",
            url: url + '/project/employee/leaveLists', //数据接口地址
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'length' //每页数据量的参数名，默认：limit
            },
            response: {
                statusCode: 100000 //重新规定成功的状态码为 200，table 组件默认为 0
            },
            method: 'POST',
            parseData: function(res){
				return {
					"code": res.code, //解析接口状态
                    "data": res.data.data,
                    "msg": res.msg,
                    "count":res.data.recordsTotal
				};
            },
            where: {
                start:0,
                draw:1,
                projectId:projectId,
                professionId: null,
                status: null,
                backStatus: null,
                search: "",
                token:getToken()
            },
            toolbar: '#toolbar',
            defaultToolbar: ['filter'],
            page: true, //开启分页
            limit: 10, //默认每页记录条数
            limits: [10, 20, 50], //每页记录条数可选数量
            cols: [
                [ //表头
                    { field: '', title: '编号', type: 'numbers',width:'8%'},
                    { field: 'projectName', title: '项目名称', },
                    { field: 'jobNumber', title: '工号', },
                    { field: 'employeeName', title: '姓名', },
                    { field: 'professionName', title: '工种', },
                    { field: 'employeeStatus', title: '工作状态',templet(d){
                        return `${d.employeeStatus==1?"在岗":d.employeeStatus==2?"代岗":d.employeeStatus==3?"离职":d.employeeStatus==4?"请假":""}`
                    }},
                    { field: 'preLeaveTime', title: '预计请假时间'},
                    { field: 'preBackTime', title: '预计销假时间'},
                    { field: 'backTime', title: '销假时间'},
                    { field: 'remark', title: '备注'},
                    { field: 'backStatus', title: '是否请假',templet(d){
                        return `${d.backStatus==0?"未销假":"已销假"}`
                    }},
                    { field: 'status', title: '审批结果',templet(d){
                        return `${d.status==0?"未审核":d.status==1?"审核通过":"审核未通过"}`
                    }}
                ]
            ],
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 100000, //成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            done:function(){
                permission();
            }
        });

        $('body').on('click','#search',function(){
            var professionId=Number($('#peopleType option:selected').val());
            var search=$(this).prev().val();
            table.reload('lists',{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where:{
                    "professionId":professionId==0?null:professionId,
                    "search":search,
                    "token":getToken()
                }
            })
        })
        $('body').on('click', '.applicationForLeave', function() {
            layer.open({
                type: 1,
                title: "请假申请",
                area: ['40%', '70%'],
                content: `
                    <form class="layui-form layerOpen" action="">
                        <div class="layui-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">请假人员查询</label>
                                <div class="layui-input-block">
                                    <input type='text' placeholder='请输入姓名或工号' id='dayTime' class='layui-input'>
                                    <ul class='layerOpen_ul_list'></ul>
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">预计请假时间</label>
                                <div class="layui-input-block">
                                    <input type='date' id='preLeaveTime' class='layui-input'>
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">预计销假时间</label>
                                <div class="layui-input-block">
                                    <input type='date' id='preBackTime' class='layui-input'>
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">请假信息备注</label>
                                <div class="layui-input-block">
                                    <textarea id='remark' class='layui-textarea'></textarea>
                                </div>
                            </div>
                        </div>
                    </form>
                `,
                btn: ['确认', '取消'],
                skin: 'my-skin',
                yes: function(index, layero) {
                    var employeeId = Number($('#dayTime').data('id'));
                    var projectId = $.parseJSON(localStorage.getItem('login_msg')).projectId;
                    var preLeaveTime = $('#preLeaveTime').val();
                    var preBackTime = $('#preBackTime').val();
                    var remark = $('#remark').val();
                    $.ajax({
                        type: "post",
                        url: url + '/project/employee/addLeave',
                        data: {
                            employeeId: employeeId,
                            projectId: Number(projectId),
                            preLeaveTime: preLeaveTime,
                            preBackTime: preBackTime,
                            remark: remark,
                            token:getToken()
                        },
                        success: function(r) {
                            if(r.code == 100000) {
                                tips('添加请假',r);
                                setTimeout(function(){
                                    table.reload('lists');
                                    layer.closeAll();
                                },2000)
                            } else {
                                tips('添加请假',r);
                            }
                        }
                    })
                }
            })
            $('#dayTime').change(function(){
                var val=$(this).val();
                var this_ind=$(this);
                var this_next=$(this).next();
                $.ajax({
                    type:"post",
                    url:url+'/project/employee/search',
                    data:{
                        projectId:Number($.parseJSON(localStorage.getItem('login_msg')).projectId),
                        search:val,
                        token:getToken()
                    },
                    success:function(r){
                        this_next.show();
                        if(r.data==""||r.data==null){
                            this_next.html('未查找到此人');
                        }else{
                            var li='';
                            for(var i=0;i<r.data.length;i++){
                                li+=`<li data-id=${r.data[i].id}>${r.data[i].name}</li>`
                            }
                            this_next.html(li);
                            $('ul li').click(function(){
                                this_ind.val($(this).html());
                                this_ind.attr('data-id',$(this).data('id'));
                                $('ul').hide();
                            })
                        }
                    }
                })
            })
        })
    });
</script>

</html>